package common.utils;

import java.io.InputStream;
import java.net.URL;

public class ResourceUtil {
    /**
     * 获取内置资源
     *
     * @param path
     * @return
     */
    public static InputStream GetStream(String path) throws Exception {
        URL url = ResourceUtil.class.getClassLoader().getResource(path);
        if (url == null)
            throw new Exception("内置资源获取失败");
        return url.openStream();
    }

    /**
     * 获取内置资源
     *
     * @param path
     * @return
     */
    public static String getText(String path) {
        try {
            return BinaryUtil.getText(GetStream(path));
        } catch (Exception e) {
            return e.getMessage();
        }
    }
}
